package week7th.jsjf;

import java.util.Scanner;
import java.util.StringTokenizer;

public class BinaryTreeTest {
    public static void main(String[] args) {
        LinkedBinaryTree a = new LinkedBinaryTree(1);
        LinkedBinaryTree b = new LinkedBinaryTree(2);
        LinkedBinaryTree c = new LinkedBinaryTree(3);
        LinkedBinaryTree d = new LinkedBinaryTree(4);
        LinkedBinaryTree e = new LinkedBinaryTree(5);

        LinkedBinaryTree de = new LinkedBinaryTree(9, d, e);
        LinkedBinaryTree bc = new LinkedBinaryTree(8, c, b);
        LinkedBinaryTree bcde = new LinkedBinaryTree(7, bc, de);
        LinkedBinaryTree abcde = new LinkedBinaryTree(6, bcde, a);

        String zhi = "/\\";
        System.out.println("       " + abcde.root);
        System.out.println("       " + zhi);
        System.out.println("    " + bcde.root + "    " + a.root);
        System.out.println("    " + zhi);
        System.out.println("  " + bc.root + "   " + de.root);
        System.out.println("  " + zhi + "  " + zhi);
        System.out.println(" " + c.root + " " + b.root + "  " + d.root + " " + e.root);

        System.out.println("深度：" + "\n" + abcde.getHeight());
        System.out.println("1是叶子吗？" + a.root.isLeaf());
        System.out.println("8是叶子吗？" + bc.root.isLeaf());
        System.out.println("是否包含9?" + abcde.contains(9));

        abcde.postOrderTraversal(abcde.root);
        System.out.println("后序");
        abcde.preOrderTraversal(abcde.root);
        System.out.println("前序");
        abcde.inOrderTraversal(abcde.root);
        System.out.println("中序");

        LinkedBinaryTree<String> l = new LinkedBinaryTree<>();

        String[] pre = {"A", "B", "D", "H", "I", "E", "J", "M", "N", "C", "F", "G", "K", "L"};
        String[] in = {"H", "D", "I", "B", "E", "M", "J", "N", "A", "F", "C", "K", "G", "L"};

        l.buildTree(in, pre);
        l.inOrderTraversal(l.root);
        System.out.println();
        l.preOrderTraversal(l.root);
        System.out.println();
        l.postOrderTraversal(l.root);
    }

}
